import java.util.Calendar;


public class StatisticGathering {
	public int key = 0;
	public boolean major = true;
	public int scale;
	public int count = 0; 
	public int[] notes=new int[1];
	public int[] volume=new int[1];
	public int[] duration=new int[1];
	public int lastPitch=0;
	public int lastDur=0;
	public long lastBeatTime;
	public int bpm=100;
	public boolean learn=false;

	public void receive(int pitch, int velocity, int dur){
		count=count+1;
		pitch=pitch-scale;
		int[] temp;		
		if (count>0){
		// update notes
			temp = notes;
			notes = new int[notes.length+1];
			System.arraycopy(temp, 0, notes, 0, temp.length);
			notes[notes.length-1]=pitch;
			
		// update volume
			temp = volume;
			volume = new int[volume.length+1];
			System.arraycopy(temp, 0, volume, 0, temp.length);
			volume[volume.length-1]=velocity;
			
			if (count>1){
			// update duration
				temp = duration;
				duration = new int[duration.length+1];
				System.arraycopy(temp, 0, duration, 0, temp.length);
				duration[duration.length-2]=dur*bpm/100;
//				duration[duration.length-2]=dur;

				while (duration[duration.length-2]>3000){
					duration[duration.length-2]=duration[duration.length-2]/2;
				}
			}
			else {
				duration[0]=250;
			}
		}
		else {
			notes[0]=pitch;
			volume[0]=velocity;
			duration[0]=dur*bpm/100;
		}
		

				
		
	}
	
	public void setBeat(int bpm){
		this.bpm=bpm;
	}
	
	public void init(){
		key = 0;
		count = 0; 
		notes = new int[1];
		volume = new int[1];
		duration=new int[1];
		lastPitch=0;
		bpm=100;
		lastDur=0;
	}
}
